package com.wfc.servlet.dish;

import com.wfc.entity.Dish;
import com.wfc.service.DishService;
import com.wfc.service.serviceImpl.DishServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/mohu")
public class MohuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String like=req.getParameter("like");
        DishService dishService = new DishServiceImpl();
        List<Dish> dishes = dishService.selectLike1(like);
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter printWriter=resp.getWriter();
        HttpSession session = req.getSession();
        session.setAttribute("dishes",dishes);
        session.setAttribute("like",like);
        String mag="";
        if (dishes.size()>0){
            mag="1";
        }

        printWriter.println(mag);


        printWriter.flush();
        printWriter.close();



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
